package se.webbzon.oschi01.worldeditor;

import java.nio.ByteBuffer;

import se.webbzon.oschi01.worldobject.WorldObject;
import se.webbzon.oschi01.worldobject.WorldStaticObject;

public abstract class WorldStaticObjectDeflation extends WorldObjectDeflation {
	
	private double x,y,z;
	private double width,height,depth;
	private double ex,ey,ez,angle;
	
	private boolean visible, solid;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public WorldStaticObjectDeflation(	int deflationProperties, 
										WorldObject[] dependencies) {
		super(deflationProperties,dependencies);
	}
	
	public WorldStaticObjectDeflation(	int deflationProperties,
										WorldObject[] dependencies,
										WorldStaticObject instance) {
		super(deflationProperties,dependencies);
		x = instance.getX();
		y = instance.getY();
		z = instance.getZ();
		width = instance.getWidth();
		height = instance.getHeight();
		depth = instance.getDepth();
		ex = instance.getEX();
		ey = instance.getEY();
		ez = instance.getEZ();
		angle = instance.getAngle();
		
		visible = instance.isVisible();
		solid = instance.isSolid();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the x-position of this deflated static world object. **/
	public double getX() {
		return x;
	}
	
	/** Returns the y-position of this deflated static world object. **/
	public double getY() {
		return y;
	}
	
	/** Returns the z-position of this deflated static world object. **/
	public double getZ() {
		return z;
	}
	
	/** Returns the width of this deflated static world object. **/
	public double getWidth() {
		return width;
	}
	
	/** Returns the height of this deflated static world object. **/
	public double getHeight() {
		return height;
	}
	
	/** Returns the depth of this deflated static world object. **/
	public double getDepth() {
		return depth;
	}
	
	/** Returns the x-position of the Euler vector describing the rotation
	 * axis for this deflated static world object. **/
	public double getEX() {
		return ex;
	}
	
	/** Returns the y-position of the Euler vector describing the rotation
	 * axis for this deflated static world object. **/
	public double getEY() {
		return ey;
	}
	
	/** Returns the z-position of the Euler vector describing the rotation
	 * axis for this deflated static world object. **/
	public double getEZ() {
		return ez;
	}
	
	/** Returns the rotation angle of this deflated static world object. **/
	public double getAngle() {
		return angle;
	}
	
	/** Returns true if this deflated static world object is visible. **/
	public boolean isVisible() {
		return visible;
	}
	
	/** Returns true if this deflated static world object is solid. **/
	public boolean isSolid() {
		return solid;
	}
	
	@Override public void inflate(ByteBuffer buff) {
		x = buff.getDouble();
		y = buff.getDouble();
		z = buff.getDouble();
		width = buff.getDouble();
		height = buff.getDouble();
		depth = buff.getDouble();
		ex = buff.getDouble();
		ey = buff.getDouble();
		ez = buff.getDouble();
		angle = buff.getDouble();
		
		visible = buff.get()!=0;
		solid = buff.get()!=0;
	}

	@Override public ByteBuffer deflate(int allocate) {
		ByteBuffer buff = ByteBuffer.allocate(allocate + 82);
		
		buff.putDouble(x);
		buff.putDouble(y);
		buff.putDouble(z);
		buff.putDouble(width);
		buff.putDouble(height);
		buff.putDouble(depth);
		buff.putDouble(ex);
		buff.putDouble(ey);
		buff.putDouble(ez);
		buff.putDouble(angle);
		
		buff.put(visible ? (byte) 1 : (byte) 0);
		buff.put(solid ? (byte) 1 : (byte) 0);
		
		return buff;
	}

}
